﻿using APIShoppingSystem.GetSession;
using APIShoppingSystem.Model;
using IShoppingBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ShoppingEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APIShoppingSystem.Controllers
{
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class DistributionInfoController : ControllerBase
	{
		private IDistributionInfoBll _distributionInfoBll;
		public DistributionInfoController(IDistributionInfoBll distributionInfoBll)
		{
			_distributionInfoBll = distributionInfoBll;
		}

		/// <summary>
		/// 分页显示列表数据
		/// </summary>
		/// <param name="page"></param>
		/// <param name="limit"></param
		/// <returns></returns>
		[HttpGet]
		public IActionResult GetDistributionInfoList(int page, int limit)
		{
			int count;

			//获取当前登录人信息
			UserInfo userInfo = this.GetSessionUserInfo();
			if (userInfo == null)
			{
				return new JsonResult(new
				{
					code = 0,
					msg = "成功",
					count = 0,
					data = new List<object>()
				});
			}
			object distributionInfos = _distributionInfoBll.GetDistributionInfoByPage(page, limit, out count);

			return new JsonResult(new
			{
				code = 0,
				msg = "成功",
				count = count,
				data = distributionInfos
			});
		}


		/// <summary>
		/// 商品已经送到
		/// </summary>
		/// <param name="distributionInfoId"></param>
		/// <param name="State"></param>
		/// <returns></returns>
		[HttpPost]
		public IActionResult Delivered([FromForm] string distributionInfoId)
		{
			CustomActionResult res = new CustomActionResult();
			bool iSuccess = _distributionInfoBll.GoodDelivered(distributionInfoId);
			if (iSuccess)
			{
				res.IsSuccess = true;
				res.Status = 1;
				res.Msg = "成功";
				return new JsonResult(res);
			}
			return new JsonResult(res);
		}


		/// <summary>
		/// 获取状态下拉选
		/// </summary>
		/// <returns></returns>
		[HttpGet]
		public IActionResult GetStatusSelectOption()
		{
			CustomActionResult res = new CustomActionResult();
			var options = _distributionInfoBll.GetStatusSelectOption();
			if (options != null)
			{
				res.Datas = options;
				res.IsSuccess = true;
				res.Status = 1;
				res.Msg = "成功";
			}

			return new JsonResult(res);
		}


	}
}
